package com.biwano.swapmyjob.beans.user;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.biwano.swapmyjob.beans.BaseBean;
import com.biwano.swapmyjob.dao.LinkDao;
import com.biwano.swapmyjob.objects.Link;
import com.biwano.swapmyjob.tools.UrlHelper;


@ManagedBean
@RequestScoped
public class LinkBean {
	
	@EJB
	LinkDao linkDao;
	
	@ManagedProperty(value="#{userBean}")
	public UserBean userBean;
	
	public void action(String id)
	{
		String redirect = UrlHelper.getHomeUrl();
		try
		{
			Link link = linkDao.getLink(id);
			userBean.load(link.getLogin());
		}
		catch (Exception e)
		{
			BaseBean.addError("generalerror", "link","linkexpired");
			e.printStackTrace();
		}
		BaseBean.redirect(redirect);
	}

	public UserBean getUserBean() {
		return userBean;
	}

	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}



	
}
